Skip to content

Conversation

scott-ferguson-unity
Copy link
Collaborator

@scott-ferguson-unity scott-ferguson-unity commented Jun 24, 2025

This is a backport of #2153

The call to mono_class_inflate_generic_method_checked will set error when there are invalid types (e.g. typeof(void)/typeof(int*)) passed in. This should not be an assert, we should all to the "Invalid generic arguments" message below. This does loose the error returned by mono_class_inflate_generic_method_checked but that error isn't user
friendly. It would report be something like:

"MVAR 1 cannot be expanded with type 0x1"

We can just report the more readable error to the user.

Note I also had to remove the "typeArguments" message from the error. When this error is freed Mono will attempt to deallocate that value, but since it's not a allocated value our allocator will crash (In Unity we replace Mono's allocators with our own).

Upstream issue: dotnet/runtime#71339
Upstream PR: dotnet/runtime#116788

  • Should this pull request have release notes?
    • Yes
    • No
  • Do these changes need to be back ported?
    • Yes
    • No
  • Do these changes need to be upstreamed to mono/mono or dotnet/runtime repositories?
    • Yes
    • No

Reviewers: please consider these questions as well! ❤️

Release notes

Fixed UUM-109251 @scott-ferguson-unity:
Mono: Prevent crash when Method.MakeGenericMethod is called with invalid generic argument types

@scott-ferguson-unity scott-ferguson-unity changed the title Remove Assert in Method.MakeGeneric on Invalid Args [6000.1] Remove Assert in Method.MakeGeneric on Invalid Args Jun 24, 2025
The call to mono_class_inflate_generic_method_checked will set error
when there are invalid types (e.g. typeof(void)/typeof(int*)) passed
in.  This should not be an assert, we should all to the "Invalid
generic arguments" message below.   This does loose the error returned
by mono_class_inflate_generic_method_checked but that error isn't user
friendly.  It would report be something like:

    "MVAR 1 cannot be expanded with type 0x1"

We can just report the more readable error to the user.

Note I also had to remove the "typeArguments" message from the error.
When this error is freed Mono will attempt to deallocate that value, but
since it's not a allocated value our allocator will crash (In Unity we
replace Mono's allocators with our own).
@scott-ferguson-unity scott-ferguson-unity force-pushed the 6000.1/remove-assert-on-invalid-method-generic-args branch from 1da3028 to 8050386 Compare July 28, 2025 12:42
@scott-ferguson-unity
Copy link
Collaborator Author

This fix isn't going to land before Unity 6.1 support ends - not merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant